import pandas as pd
import matplotlib.pyplot as plt

plt.rcParams['font.sans-serif'] = ['Microsoft YaHei']
plt.rcParams['axes.unicode_minus'] = False

# 导入数据
data = pd.read_excel('第二章 图表(前15).xlsx', sheet_name='12 菱形走势图', usecols='B:C', skiprows=1)

# 设置图形大小
plt.figure(figsize=(10, 6))

# 设置Y轴范围
plt.ylim(0, 1)

# 绘制菱形走势图
plt.scatter(data.iloc[:, 0], data.iloc[:, 1], marker='d', s=100, facecolors='none', edgecolors='red')

# 绘制从菱形到X轴的连线
for x, y in zip(data.iloc[:, 0], data.iloc[:, 1]):
    plt.plot([x, x], [0, y - 0.02], color='red', linestyle='-')
    plt.text(x, y + 0.02, f'{y * 100:.2f}%', ha='center', va='bottom', fontsize=10, color='green')

# 隐藏除X轴以外的边框
ax = plt.gca()  # 获取当前的坐标轴
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_visible(False)

# 隐藏Y轴标签
plt.yticks([])

# 导出图片
#plt.savefig('D:/python charm/01/可视化/第二章/图片/菱形走势图.png', dpi=300, bbox_inches='tight')

plt.show()